package com.abc.core.instance.bo;

import com.abc.core.def.Dna;
import com.abc.core.util.InstSerializer;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * 实例
 */
@JsonSerialize(using = InstSerializer.class)
@Data
public class Inst implements Cloneable {
    private String dnaCode;
    private String dnaName;
    /**
     * Inst类型,不同的子类适用于不同的使用场景
     */
    private String instType;
    private Dna dna;
    private Integer total;

    @JsonIgnore
    private Cell parentCell;

    private List<Cell> cells = new ArrayList<>();

    public Inst() {
    }

    public Inst(String dnaCode, String dnaName) {
        this.dnaCode = dnaCode;
        this.dnaName = dnaName;
        parentCell = new Cell();
    }

    public Inst(String instType, Dna dna, Cell parentCell) {
        this.instType = instType;
        this.dna = dna;
        this.parentCell = parentCell;
    }

    public Inst(Dna dna) {
        // TODO return null;
    }

    public Cell getSingleCell() {
        if (this.cells.size() != 1) {
            throw new RuntimeException("非唯一值Cell");
        }
        // Cell cell = new Cell();
        // cells.add(0, cell);
        return cells.get(0);
    }

    public void addCell(Cell anotherCell) {
        cells.add(anotherCell);
    }

}
